﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mani.Patient.Business.Domain.Entity;
using Mani.Patient.Business.Dao;
using Spring.Transaction.Interceptor;

namespace Mani.Patient.Business.Services {

    public interface IQuestionService {

        IList<QuestionType> GetQuestionTypes();
        QuestionType GetQuestionType(int id);
        IList<Question> GetQuestionsByType(int questionTypeId);
        Question GetQuestion(int id);
        void CreateQuestionType(QuestionType qt);
        void DeleteQuestionType(QuestionType qt);
        void DeleteQuestion(Question q);
        void CreateQuestion(Question q);
    }

    public class QuestionService : IQuestionService {

        public QuestionTypeDao QuestionTypeDao { get; set; }
        public QuestionDao QuestionDao { get; set; }

        #region IQuestionService Members

        public IList<QuestionType> GetQuestionTypes() {
            return QuestionTypeDao.FindAll();
        }

        public Question GetQuestion(int id) {
            return QuestionDao.FindById(id);
        }

        public QuestionType GetQuestionType(int id) {
            return QuestionTypeDao.FindById(id);
        }

        public IList<Question> GetQuestionsByType(int questionTypeId) {
            QuestionType qt = QuestionTypeDao.FindById(questionTypeId);
            return QuestionDao.GetQuestionsByType(qt);
        }

        [Transaction(ReadOnly = false)]
        public void CreateQuestionType(QuestionType qt) {
            QuestionTypeDao.SaveOrUpdate(qt);
        }

        [Transaction(ReadOnly = false)]
        public void DeleteQuestionType(QuestionType qt) {
            QuestionTypeDao.Delete( qt );
        }

        [Transaction(ReadOnly = false)]
        public void DeleteQuestion(Question q) {
            QuestionDao.Delete(q);
        }

        [Transaction(ReadOnly = false)]
        public void CreateQuestion(Question q) {
            QuestionDao.SaveOrUpdate(q);
        }

        #endregion
    }
}
